﻿using ZYCommon;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace TextEditor
{
    

    public class A_SetForeColor : A_Action
    {
        public override string ActionName()
        {
            return "forecolor";
        }

        public override A_Action Clone()
        {
            A_SetForeColor color = new A_SetForeColor();
            color.BaseCloneFrom(this);
            return color;
        }

        public override bool Execute()
        {
            base.myOwnerDocument.SetSelectionColor(StringCommon.ColorFromHtml(base.Param1, SystemColors.WindowText));
            return true;
        }

        public override bool isEnable()
        {
            return base.myOwnerDocument.CanModify();
        }

        public override bool UIExecute()
        {
            using (ColorDialog dialog = new ColorDialog())
            {
                dialog.FullOpen = true;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    base.myOwnerDocument.SetSelectionColor(dialog.Color);
                    return true;
                }
            }
            return false;
        }
    }
}

